home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / as / sprite / RCS / as.c,v < prev    next >
Encoding:
Text File  |  1990-06-28  |  8.0 KB  |  319 lines

  1. head     1.2;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.2
  10. date     90.06.28.15.25.12;  author rab;  state Exp;
  11. branches ;
  12. next     1.1;
  13.  
  14. 1.1
  15. date     90.02.12.21.18.59;  author rab;  state Exp;
  16. branches ;
  17. next     ;
  18.  
  19.  
  20. desc
  21. @@
  22.  
  23.  
  24. 1.2
  25. log
  26. @Added some missing opcodes and fixed some misc bugs.
  27. @
  28. text
  29. @/* as.c - GAS main program.
  30.    Copyright (C) 1987 Free Software Foundation, Inc.
  31.  
  32. This file is part of GAS, the GNU Assembler.
  33.  
  34. GAS is free software; you can redistribute it and/or modify
  35. it under the terms of the GNU General Public License as published by
  36. the Free Software Foundation; either version 1, or (at your option)
  37. any later version.
  38.  
  39. GAS is distributed in the hope that it will be useful,
  40. but WITHOUT ANY WARRANTY; without even the implied warranty of
  41. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  42. GNU General Public License for more details.
  43.  
  44. You should have received a copy of the GNU General Public License
  45. along with GAS; see the file COPYING.  If not, write to
  46. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  47.  
  48. /*
  49.  * Main program for AS; a 32-bit assembler of GNU.
  50.  * Understands command arguments.
  51.  * Has a few routines that don't fit in other modules because they
  52.  * are shared.
  53.  *
  54.  *
  55.  *            bugs
  56.  *
  57.  * : initialisers
  58.  *    Since no-one else says they will support them in future: I
  59.  * don't support them now.
  60.  *
  61.  */
  62.  
  63. #define COMMON
  64. #include "as.h"
  65. #include "struc-symbol.h"
  66. #include "write.h"
  67.         /* Warning!  This may have some slightly strange side effects
  68.            if you try to compile two or more assemblers in the same
  69.            directory!
  70.          */
  71.  
  72. static char * gdb_symbol_file_name;
  73. int had_warnings;
  74. char *myname;        /* argv[0] */
  75. extern char version_string[];
  76.  
  77. main(argc,argv)
  78. int    argc;
  79. char    **argv;
  80. {
  81.     int    work_argc;    /* variable copy of argc */
  82.     char    **work_argv;    /* variable copy of argv */
  83.     char    *arg;        /* an arg to program */
  84.     char    a;        /* an arg flag (after -) */
  85.  
  86.     char    *stralloc();    /* Make a (safe) copy of a string. */
  87.     long int gdb_begin();
  88.     void    symbol_begin();
  89.     void    read_begin();
  90.     void    write_object_file();
  91.  
  92.     myname=argv[0];
  93.     bzero (flagseen, sizeof(flagseen)); /* aint seen nothing yet */
  94.     out_file_name    = "a.out";    /* default .o file */
  95.     symbol_begin();        /* symbols.c */
  96.     subsegs_begin();        /* subsegs.c */
  97.     read_begin();            /* read.c */
  98.     md_begin();            /* MACHINE.c */
  99.     input_scrub_begin();        /* input_scrub.c */
  100.     gdb_symbol_file_name = 0;
  101.     /*
  102.      * Parse arguments, but we are only interested in flags.
  103.      * When we find a flag, we process it then make it's argv[] NULL.
  104.      * This helps any future argv[] scanners avoid what we processed.
  105.      * Since it is easy to do here we interpret the special arg "-"
  106.      * to mean "use stdin" and we set that argv[] pointing to "".
  107.      * After we have munged argv[], the only things left are source file
  108.      * name(s) and ""(s) denoting stdin. These file names are used
  109.      * (perhaps more than once) later.
  110.      */
  111.     work_argc = argc-1;        /* don't count argv[0] */
  112.     work_argv = argv+1;        /* skip argv[0] */
  113.     for (;work_argc--;work_argv++) {
  114.         arg = * work_argv;    /* work_argv points to this argument */
  115.  
  116.         if (*arg!='-')        /* Filename. We need it later. */
  117.             continue;    /* Keep scanning args looking for flags. */
  118.         if (arg[1] == '-' && arg[2] == 0) {
  119.             /* "--" as an argument means read STDIN */
  120.             /* on this scan, we don't want to think about filenames */
  121.             * work_argv = "";    /* Code that means 'use stdin'. */
  122.             continue;
  123.         }
  124.                 /* This better be a switch. */
  125.         arg ++;        /* -> letter. */
  126.  
  127.         while (a = * arg)  {/* scan all the 1-char flags */
  128.             arg ++;    /* arg -> after letter. */
  129.             a &= 0x7F;    /* ascii only please */
  130.             if (flagseen[a])
  131.                 as_warn("%s: Flag option -%c has already been seen!",myname,a);
  132.             flagseen[a] = TRUE;
  133.             switch (a) {
  134.             case 'f':
  135.                 break;    /* -f means fast - no need for "app" preprocessor. */
  136.  
  137.             case 'D':
  138.                 /* DEBUG is implemented: it debugs different */
  139.                 /* things to other people's assemblers. */
  140.                 break;
  141.  
  142.             case 'G':    /* GNU AS switch: include gdbsyms. */
  143.                 if (*arg)    /* Rest of argument is file-name. */
  144.                     gdb_symbol_file_name = stralloc (arg);
  145.                 else if (work_argc) {    /* Next argument is file-name. */
  146.                     work_argc --;
  147.                     * work_argv = NULL; /* Not a source file-name. */
  148.                     gdb_symbol_file_name = * ++ work_argv;
  149.                 } else
  150.                     as_warn( "%s: I expected a filename after -G",myname);
  151.                 arg = "";    /* Finished with this arg. */
  152.                 break;
  153.  
  154.  
  155. #ifndef WORKING_DOT_WORD
  156.             case 'k':
  157.                 break;
  158. #endif
  159.  
  160.             case 'L': /* -L means keep L* symbols */
  161.                 break;
  162.  
  163.             case 'o':
  164.                 if (*arg)    /* Rest of argument is object file-name. */
  165.                     out_file_name = stralloc (arg);
  166.                 else if (work_argc) {    /* Want next arg for a file-name. */
  167.                     * work_argv = NULL; /* This is not a file-name. */
  168.                     work_argc--;
  169.                     out_file_name = * ++ work_argv;
  170.                 } else
  171.                     as_warn("%s: I expected a filename after -o. \"%s\" assumed.",myname,out_file_name);
  172.                 arg = "";    /* Finished with this arg. */
  173.                 break;
  174.  
  175.             case 'R':
  176.                 /* -R means put data into text segment */
  177.                 break;
  178.  
  179.             case 'v':
  180. #ifdef    VMS
  181.                 {
  182.                 extern char *compiler_version_string;
  183.                 compiler_version_string = arg;
  184.                 }
  185. #else /* not VMS */
  186.                 fprintf(stderr,version_string);
  187.                 if(*arg && strcmp(arg,"ersion"))
  188.                     as_warn("Unknown -v option ignored");
  189. #endif
  190.                 while(*arg) arg++;    /* Skip the rest */
  191.                 break;
  192.  
  193.             case 'W':
  194.                 /* -W means don't warn about things */
  195.                 break;
  196.  
  197.             default:
  198.                 --arg;
  199.                 if(md_parse_option(&arg,&work_argc,&work_argv)==0)
  200.                     as_warn("%s: I don't understand '%c' flag!",myname,a);
  201.                 if(arg && *arg)
  202.                     arg++;
  203.                 break;
  204.             }
  205.         }
  206.         /*
  207.          * We have just processed a "-..." arg, which was not a
  208.          * file-name. Smash it so the
  209.          * things that look for filenames won't ever see it.
  210.          *
  211.          * Whatever work_argv points to, it has already been used
  212.          * as part of a flag, so DON'T re-use it as a filename.
  213.          */
  214.         *work_argv = NULL; /* NULL means 'not a file-name' */
  215.     }
  216.     if (gdb_begin(gdb_symbol_file_name) == 0)
  217.         flagseen ['G'] = 0;    /* Don't do any gdbsym stuff. */
  218.     /* Here with flags set up in flagseen[]. */
  219.     perform_an_assembly_pass(argc,argv); /* Assemble it. */
  220.  
  221.     if (had_warnings) {
  222.         fprintf(stderr, "NO OBJECT FILE CREATED!\n"); 
  223.         exit(1);
  224.     }
  225.     if (seen_at_least_1_file())
  226.         write_object_file();/* relax() addresses then emit object file */
  227.     input_scrub_end();
  228.     md_end();            /* MACHINE.c */
  229. #ifndef    VMS
  230.     exit(0);            /* WIN */
  231. #else    /* VMS */
  232.     exit(1);            /* WIN */
  233. #endif    /* VMS */
  234. }
  235.  
  236.  
  237. /*            perform_an_assembly_pass()
  238.  *
  239.  * Here to attempt 1 pass over each input file.
  240.  * We scan argv[*] looking for filenames or exactly "" which is
  241.  * shorthand for stdin. Any argv that is NULL is not a file-name.
  242.  * We set need_pass_2 TRUE if, after this, we still have unresolved
  243.  * expressions of the form (unknown value)+-(unknown value).
  244.  *
  245.  * Note the un*x semantics: there is only 1 logical input file, but it
  246.  * may be a catenation of many 'physical' input files.
  247.  */
  248. perform_an_assembly_pass (argc, argv)
  249. int    argc;
  250. char **    argv;
  251. {
  252.     char *    buffer;        /* Where each bufferful of lines will start. */
  253.     void    read_a_source_file();
  254.     int saw_a_file = 0;
  255.  
  256.     text_fix_root        = NULL;
  257.     data_fix_root        = NULL;
  258.     need_pass_2        = FALSE;
  259.  
  260.     argv++;            /* skip argv[0] */
  261.     argc--;            /* skip argv[0] */
  262.     while (argc--) {
  263.         if (*argv) {        /* Is it a file-name argument? */
  264.             /* argv -> "" if stdin desired, else -> filename */
  265.             if (buffer = input_scrub_new_file (*argv) ) {
  266.                 saw_a_file++;
  267.                 read_a_source_file(buffer);
  268.             }
  269.         }
  270.         argv++;            /* completed that argv */
  271.     }
  272.     if(!saw_a_file)
  273.         if(buffer = input_scrub_new_file("") )
  274.             read_a_source_file(buffer);
  275. }
  276.  
  277. /*
  278.  *            stralloc()
  279.  *
  280.  * Allocate memory for a new copy of a string. Copy the string.
  281.  * Return the address of the new string. Die if there is any error.
  282.  */
  283.  
  284. char *
  285. stralloc (str)
  286. char *    str;
  287. {
  288.     register char *    retval;
  289.     register long int    len;
  290.  
  291.     len = strlen (str) + 1;
  292.     retval = xmalloc (len);
  293.     (void)strcpy (retval, str);
  294.     return (retval);
  295. }
  296.  
  297. lose()
  298. {
  299.     as_fatal( "%s: 2nd pass not implemented - get your code from random(3)",myname );
  300. }
  301.  
  302. /* end: as.c */
  303. @
  304.  
  305.  
  306. 1.1
  307. log
  308. @Initial revision
  309. @
  310. text
  311. @d45 1
  312. a45 1
  313.  
  314. d192 5
  315. d198 1
  316. a198 1
  317.         write_object_file();/* relax() addresses then emit object file */
  318. @
  319.